<?php
namespace Home\Controller\Notification;
use Think\Controller;

class IndexController extends Controller
{

    public function index()
    {
        if($username = cookie('username') && $pwd = cookie('pwd')){
        	
        }
        return redirect('/drm/');
    }

    public function getNotice()
    {
        if($username = cookie('username') && $pwd = cookie('pwd')){
            $drugs = M('drugs');
            $alert_time = time()+604800;//7*24*3600
            $query['period'] = array('lt',$alert_time);
            $over_drugs = $drugs->where($query)->select();
            $depots = M('depot');
            foreach ($over_drugs as $key => $val) {
            	$over_drugs[$key]['period'] = floor(($val['period'] - time())/86400);//一天24*3600
            	$depot_query['id'] = $val['depot_id'];
            	$over_drugs[$key]['depot_id'] = $depots->where($depot_query)->find()['address'];
            }
            $person['name'] = cookie('username');
            $this->assign('person',$person);
            $this->assign('notices',$over_drugs);
            return $this->display('Notification/notice');
            
        }
        return redirect('/drm/');
    }
}
